package com.derbysoft.ota.infrastructure.guice;

import java.util.Properties;

import com.google.inject.AbstractModule;
import com.google.inject.Module;
import com.google.inject.internal.Preconditions;
import com.google.inject.name.Names;
import com.googlecode.guicespring.support.PropertiesLoaders;

public abstract class Environments {

	public static final String PROJECT_NAME = "dswitch2-ota-adapter";

	public static Properties properties;

	public static void initialize() {
		properties = PropertiesLoaders.classpath("environment.properties");
	}

	/**
	 * For the case that some class can't be injected, eg, some third party classes.
	 */
	public static Properties get() {
		return Preconditions.checkNotNull(
			properties,
			"Global enviroment hasn't been initialized yet, please call Enviroments#initialize to initialize it."
		);
	}

	public static Module module() {
		return new AbstractModule() {
			@Override
			protected void configure() {
				Names.bindProperties(binder(), properties);
			}
		};
	}


}
